
import router from '@/router'
import store from './store'
// // 进度条nprogress 和样式
import nProgress from 'nprogress'
import 'nprogress/nprogress.css'
// 路由前置首位
router.beforeEach(async(to, from, next) => {
  // 开启进度条
  nProgress.start()
  const { token } = store.getters
  if (token) {
    if (to.path === '/login') {
      // 有token他还想去登录的话让他去首页
      next('/')
      nProgress.done()
    } else {
      next()
    }
  } else {
    const whiteList = ['/login', '/404']
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
      nProgress.done()
    }
  }
})

router.afterEach((from, to, next) => {
  // 关闭进度条
  nProgress.done()
})
